package com.itheima.linkNode;

import com.itheima.util.ListNode;

/**
 * @author MMXZKA
 * @date 2025-08-01 10:12
 */

//给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。
public class LeedCode206 {


    //Definition for singly-linked list.

    //递归做法
     /*   public ListNode reverseList(ListNode head) {
        return reback(head,null);
        }

        private ListNode reback(ListNode hou,ListNode qian) {
        if(hou == null) return qian;
        ListNode res = reback(hou.next,hou);
        hou.next = qian;
        return res;
    }*/

//前驱后继暂存点做法
    public ListNode reverseList(ListNode head) {
        ListNode pre = null;
        ListNode suc = head;
        ListNode mid = head;

        while (mid != null){
            suc = suc.next;
            mid.next = pre;
            pre = mid;
            mid = suc;
        }
        return pre;
    }
    }

